unit CommonUtils;

interface

procedure WriteLog(const Mess: string; ProductName: string);
function VigenerCoDec(Input, Key: string): string;

implementation

uses SysUtils, Classes, ProductUtils;

procedure WriteLog(const Mess: string; ProductName: string);
var strFileName: string;
    tsFile: TStringList;
begin
    strFileName := GetLogFileName(ProductName);
    tsFile := TStringList.Create;
    try
        if FileExists(strFileName) then tsFile.LoadFromFile(strFileName);
        tsFile.Add(TimeToStr(Time));
        tsFile.Add(Mess);
        tsFile.Add('');
        tsFile.SaveToFile(strFileName);
    finally
        tsFile.Free;
    end;
end;

function VigenerCoDec(Input, Key: string): string;
var i, j: integer;
    tmps, text: string;
    newstr: char;
begin
    text := Input;
    for i := 1 to length(text) do
    begin
        if i > length(key) then
            j := i mod length(key)
        else
            j := i;
        if ord(text[i]) = ord(key[j]) then
            newstr := text[i]
        else
            newstr := chr((ord(text[i])) xor (ord(key[j])));
        tmps := tmps + newstr;
    end;
    result := tmps;
end;

end.
